<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Tcl language</title>
<link rel="stylesheet" href="/cfg/format.css" type="text/css">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="keywords" content="Tcl, tutorial, programming language, learn Tcl, Linux">
<meta name="description" content="This chapter of the Tcl tutorial is a description of the Tcl language.">
<meta name="language" content="en">
<meta name="author" content="Jan Bodnar">
<meta name="distribution" content="global">

<script type="text/javascript" src="/lib/jquery.js"></script>
<script type="text/javascript" src="/lib/common.js"></script>

</head>

<body>

<div class="container">

<div id="wide_ad" class="ltow">
<script type="text/javascript"><!--
google_ad_client = "pub-9706709751191532";
/* 160x600, August 2011 */
google_ad_slot = "2484182563";
google_ad_width = 160;
google_ad_height = 600;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>


<div class="content">

<a href="/" title="Home">Home</a>&nbsp;
<a href="..">Contents</a>



<h1>Tcl</h1>

<p>
In this part of the Tcl tutorial, we will introduce the 
Tcl programming language. 
</p>


<h2>Goal</h2>

<p>
The goal of this tutorial is to get you started with the Tcl
programming language. The tutorial covers the core of the Tcl language. 
Variables, lists, arrays, control structures and other core features. 
It is not a complete coverage of the language. It is a quick, introductory
material. The tutorial was created on Ubuntu Linux. 
</p>

<script type="text/javascript"><!--
google_ad_client = "ca-pub-9706709751191532";
/* LargeSquare */
google_ad_slot = "5070696322";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>


<h2>Tcl</h2>

<p> 
<img src="/img/lang/tcl/logo.png" style="float: left; margin-right:10" alt="Tcl logo"> 
<b>Tcl</b> is a string based scripting language. The source code is compiled into bytecode, which
is later interpreted by the Tcl interpreter. It was created by <b>John Osterhout</b> 
in 1988. The purpose was to create a language which is easily embeddable into 
applications. But it is often used outside its original area. The language  is commonly 
used for rapid prototyping, scripted applications, GUIs and testing. 
The Tcl stands for tool command language, where
the source code of a Tcl script consists of commands. 
</p> 

<p> 
Tcl is a procedural language. It has some functional features. OOP support is planned
for the next official release. 
</p> 
 
<p> 
The official web site for both Tcl and Tk is <a href="http://tcl.tk/">tcl.tk</a> 
</p> 

<h2>Popularity</h2>

<p>
There are hundreds of programming languages in use today. Tcl does
not belong to the most popular ones. It has its own niche, where it
used. According to the <a href="http://langpop.com/">langpop.com</a> site
it scored 21. On <a href="http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html">tiobe</a>
index, it ended on the 96. place.                                                                  
</p>

<h2>Interactive interpreter</h2>

<p>
We can run Tcl commands in a script or in an interactive interpreter. 
In this tutorial, we will use the interactive Tcl session to demonstrate 
some smaller code fragments. Larger code examples are to be put in
Tcl scripts. 
</p>

<pre class="code">
$ tclsh
% puts $tcl_version
8.5
% puts $tcl_interactive
1
</pre>

<p>
This is an example of the Tcl interactive session.
</p>

<pre class="explanation">
$ tclsh
</pre>

<p>
We start the interactive session with the tclsh command.
</p>

<pre class="explanation">
% puts $tcl_version
8.5
</pre>

<p>
The prompt changes to the % character. We print the value of a special
tcl_version variable to the console. It is set to the version of the
current Tcl in use. 
</p>

<pre class="explanation">
% puts $tcl_interactive
1
</pre>

<p>
The tcl_interactive variable tells us whether we are in an interactive
mode or not. 
</p>

<h2>Tcl scripts</h2>

<p>
We will have our first simple example of a Tcl script. 
</p>

<pre class="code">
#!/usr/bin/tclsh

# first.tcl

puts "This is Tcl tutorial"
</pre>

<p>
In this script, we print a message to the console. 
</p>

<pre class="explanation">
#!/usr/bin/tclsh
</pre>

<p>
Every script in the UNIX starts with a shebang. The shebang is the first two 
characters in the script: <b>#!</b>. The shebang is followed by the path 
to the interpreter, which will execute our script. The /usr/bin/ is the
most common location for the Tcl shell. It could also be located in
/usr/local/bin/ or elsewhere. 
</p>

<pre class="explanation">
# first.tcl
</pre>

<p>
Comments in Tcl are preceded by a # character. 
</p>

<pre class="explanation">
puts "This is Tcl tutorial"
</pre>

<p>
The <code>puts</code> command prints a string to the console. 
</p>

<pre class="code">
$ which tclsh
/usr/bin/tclsh
</pre>

<p>
The path to the Tcl interpreter can be found using the which command.
</p>

<pre class="code">
$ chmod +x first.tcl 
$ ./first.tcl 
This is Tcl tutorial
</pre>

<p>
We make script executable with the chmod command. And execute it.
</p>


<h2>Sources</h2>

<p>
The following sources were used to create this tutorial:
</p>

<ul>
  <li><a href="http://www.tcl.tk/">tcl.tk</a></li>
  <li><a href="http://www.wikipedia.org/">wikipedia.org</a></li>
</ul>

<p>
In this part of the Tcl tutorial, we have introduced the Tcl language. 
</p>

<br>
<div class="center"> 
<script type="text/javascript"><!--
google_ad_client = "pub-9706709751191532";
/* horizontal */
google_ad_slot = "1734478269";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script> 
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> 
</script> 
</div> 
<br>

<div class="botNav, center">
<span class="botNavItem"><a href="/">Home</a></span> ‡ <span class="botNavItem"><a href="..">Contents</a></span> ‡ 
<span class="botNavItem"><a href="#">Top of Page</a></span>
</div>

<div class="footer">
<div class="signature">
<a href="/">ZetCode</a> last modified April 1, 2011  <span class="copyright">&copy; 2007 - 2013 Jan Bodnar</span>
</div>
</div>

</div> <!-- content -->

</div> <!-- container -->

</body>
</html>
